home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr2.arc / STRSUFF.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  806b  |  28 lines

  1. /*  File   : strsuff.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 11 April 1984
  4.     Defines: strsuff()
  5.  
  6.     strsuff(src, suffix)
  7.     checks whether suffix is a suffix of src.  If it is not, the  result
  8.     is NullS.  If it is, the result is a pointer to the character of src
  9.     where suffix starts (which is the same as src+strlen(src)-strlen(prefix) ).
  10.     See strpref.c for a comment about using if (strsuff(...)) in C.
  11. */
  12.  
  13. #include "strings.h"
  14.  
  15. char *strsuff(src, suffix)
  16.     register char *src, *suffix;
  17.     {
  18.        register int L; /* length of suffix */
  19.  
  20.        for (L = 0; *suffix++; L++)
  21.            if (!*src++) return NullS;
  22.        while (*src++) ;
  23.        for (--src, --suffix; --L >= 0; )
  24.            if (*--src != *--suffix) return NullS;
  25.        return src;
  26.     }
  27.  
  28.